In Rust, type casting is a mechanism used to convert a value from one type to another. This is often necessary when working with different types
that are compatible but not the same. However, unnecessary casts can occur when the type conversion is redundant because the compiler already knows
the type based on the context or explicit type declarations.
Unnecessary casts should be avoided in Rust code as they add unnecessary complexity, clutter the code, and can lead to confusion. They also make
the code less idiomatic and harder to read.
fn get_length(value: &str) -> usize {
let length = value.len() as usize; // Noncompliant: 'value.len()' already returns a 'usize'
length
}
Remove all unnecessary casts based on the contextual typing information, as inferred by the Rust compiler.
fn get_length(value: &str) -> usize {
let length = value.len();
length
}